Adding some more judges, here and there.
[andmenj-acm.git] / lib / Mi manual de algoritmos / version_world_finals_2009 / src / geometria / distance_point_to_line.cpp
blob4b6bef280ad2423e806f9f84f1222f51d43b1e73
1 /*
2 Returns the closest distance between point pnt and the line
3 that passes through points a and b
4 Idea by:
5 http://local.wasp.uwa.edu.au/~pbourke/geometry/pointline/
6 */
7 double distance_point_to_line(const point &a, const point &b,
8 const point &pnt){
9 double u =
10 ((pnt.x - a.x)*(b.x - a.x)+(pnt.y - a.y)*(b.y - a.y))
11 /distsqr(a, b);
12 point intersection;
13 intersection.x = a.x + u*(b.x - a.x);
14 intersection.y = a.y + u*(b.y - a.y);
15 return dist(pnt, intersection);